﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using Common;

public partial class Business_Business_Shedule : System.Web.UI.Page
{
    protected int NewsKey
    {
        get { return string.IsNullOrEmpty(Request["NewsKey"]) ? 0 : Convert.ToInt32(Request["NewsKey"]); }
    }

    protected string MenuType;

    protected Dat_News news;

    protected void Page_Load(object sender, EventArgs e)
    {
        MenuType = string.IsNullOrEmpty(Request["MenuType"]) ? "" : Request["MenuType"].ToString();

        if (!this.IsPostBack)
        {

            IList<Sys_Account>  UserList = new Account().GetNotAccount(1);
            foreach (Sys_Account account in UserList)
                MUserKey.Items.Add(new ListItem("◆ "+account.RealName,account.UserKey.ToString()));

            news = new News().SelectNews(NewsKey);

            MUserKey.SelectedValue = news.MUserKey.ToString();

            //预约处理时间
            TechOneD.Attributes.Add("onfocus", "selectDate(this)");
            TechTwoD.Attributes.Add("onfocus", "selectDate(this)");
            string H, M;
            if (WebUtility.DateTimeToString(news.TechOneTime) != "")
            {
                TechOneD.Text = WebUtility.DateTimeToString(news.TechOneTime).Split(' ')[0];
                H = WebUtility.DateTimeToString(news.TechOneTime).Split(' ')[1].Split(':')[0];
                if (H.Length == 1) H = "0" + H;
                TechOneT_H.Text = H;
                M = WebUtility.DateTimeToString(news.TechOneTime).Split(' ')[1].Split(':')[1];
                if (M.Length == 1) M = "0" + M;
                TechOneT_M.Text = M;
            }
            if (WebUtility.DateTimeToString(news.TechTwoTime) != "")
            {
                TechTwoD.Text = WebUtility.DateTimeToString(news.TechTwoTime).Split(' ')[0];
                H = WebUtility.DateTimeToString(news.TechTwoTime).Split(' ')[1].Split(':')[0];
                if (H.Length == 1) H = "0" + H;
                TechTwoT_H.Text = H;
                M = WebUtility.DateTimeToString(news.TechTwoTime).Split(' ')[1].Split(':')[1];
                if (M.Length == 1) M = "0" + M;
                TechTwoT_M.Text = M;
            }
        }
    }

    //添加
    protected void btnSubmit_Click(object sender, EventArgs e)
    {   

        Dat_News news = new Dat_News
        {
            NewsKey = NewsKey,
            MUserKey = Convert.ToInt32(MUserKey.SelectedValue),
            TechOneTime = Convert.ToDateTime(TechOneD.Text.Trim() + " " + TechOneT_H.Text + ":" + TechOneT_M.Text + ":00"),
            TechTwoTime = Convert.ToDateTime(TechTwoD.Text.Trim() + " " + TechTwoT_H.Text + ":" + TechTwoT_M.Text + ":00"),
            Content_Scheduling = Content_Scheduling.Text.Trim(),
            SheduleTime = DateTime.Now,
            SheduleUserKey = Convert.ToInt32(Session["UserKey"]),
            UserKey = Convert.ToInt32(Session["UserKey"]),
            UpdateTime = DateTime.Now,
            Type = 2
        };

        if (new News().EditNews_Shedule(news))
        {
            if (MenuType == "121")   //未完成界面
                WebUtility.JsAlertToParent("任务分配成功", "Business_NotFinish.aspx?menutype=121");
            else   //任务处理界面
                WebUtility.JsAlertToParent("任务分配成功", "Business.aspx?menutype=133&type=1,2,4,5");
        }
    }

}
